package com.yihubang.navigationcourse.fragment

import android.os.Bundle
import android.view.View
import androidx.core.app.ActivityOptionsCompat
import androidx.navigation.ActivityNavigatorExtras
import androidx.navigation.fragment.FragmentNavigator
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController
import com.yihubang.navigationcourse.R
import com.yihubang.navigationcourse.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_login.*
import kotlinx.android.synthetic.main.fragment_login.view.*

/*
 * class title: 
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/4/23.
 * PS: Not easy to write code, please indicate.
 */
class LoginFragment : BaseFragment() {
    override fun getLayoutResId() = R.layout.fragment_login

    override fun initView(rootView: View) {
        rootView.toRegisterPage.setOnClickListener {
            //两个共享元素
            //头像
            val imagePair = Pair<View, String>(regUserAvatar, "userAvatarTn")
            //用户名
            val userNamePair = Pair<View, String>(userNameInp, "userNameTn")
            val extras: FragmentNavigator.Extras =
                FragmentNavigatorExtras(imagePair, userNamePair)
            //数据
            val bundle = Bundle()
            bundle.putString("userName", userNameInp.text.toString())
            //跳转到注册页面
            findNavController().navigate(R.id.to_register_fragment, bundle, null, extras)
        }

        rootView.toForgetPage.setOnClickListener {
            //跳转到找回密码页面
            findNavController().navigate(R.id.to_forget_fragment)
        }

        rootView.toAgreementPage.setOnClickListener {
            val imagePair = androidx.core.util.Pair<View, String>(regUserAvatar, "userAvatarTn")
            //用户名
            val userNamePair = androidx.core.util.Pair<View, String>(userNameInp, "userNameTn")
            val options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                requireActivity(),
                imagePair, userNamePair
            )
            val extras = ActivityNavigatorExtras(options)
            //数据
            val bundle = Bundle()
            bundle.putString("userName", userNameInp.text.toString())
            //跳转到用户协议页面
            findNavController().navigate(R.id.to_agreement_activity, bundle, null, extras)
        }
    }
}
